import 'package:common_utils/common_utils.dart';
import 'package:dss_base/dss_base.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BadgeWidget extends StatelessWidget {
  final int num;
  final Color color;

  const BadgeWidget({
    super.key,
    required this.num,
    this.color = Colors.red,
  });

  @override
  Widget build(BuildContext context) {
    if (num < 1) return SizedBox.shrink();
    var text = TextUtil.formatComma3(num);
    var size = 16.w;
    double width = size + (text.length - 1) * 6.w;
    double height = size;
    return Container(
      alignment: Alignment.center,
      width: width,
      height: height,
      decoration: BoxDecoration(
        color: color,
        shape: BoxShape.rectangle,
        borderRadius: BorderRadius.circular(size / 2),
      ),
      child: Text(
        text,
        textAlign: TextAlign.center,
        style: TextStyle(
          color: Colors.white,
          fontSize: 10.sp,
        ),
      ),
    );
  }

  static translationX(int num) {
    if (num < 1) return 0.0;
    var text = TextUtil.formatComma3(num);
    var size = 16.w;
    double width = size + (text.length - 1) * 6.w;
    return width / 4;
  }
}
